/*!
 * \file jboss_comm.h
 *
 * \brief jboss 模块解析
 *
 * All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.\n
 *
 * \version 2.0
 * \author geyh
 * \date 2015/11/05
 *
 */

#ifndef __JBOSSMQ_COMM_H_
#define __JBOSSMQ_COMM_H_

#include "frbyte_buffer.h"
#include "frreport_comm.h"

//PUB

//SUB
#define APM_REPORT_KEY_SUB_MQ                     APM_REPORT_KEY_SUB".mq"
#define APM_REPORT_KEY_SUB_QUEUE                  APM_REPORT_KEY_SUB_MQ".topic"

//NOTIFY
#define APM_REPORT_KEY_NTF_MQ                     APM_REPORT_KEY_NOTIFY".mq"
#define APM_REPORT_KEY_NTF_QUEUE                  APM_REPORT_KEY_NTF_MQ".queue"
#define APM_REPORT_KEY_NTF_TOPIC                  APM_REPORT_KEY_NTF_MQ".topic"
#define APM_REPORT_KEY_NTF_TYPE                   APM_REPORT_KEY_NTF_MQ".message.type.1"
#define APM_REPORT_KEY_NTF_TEXT                   APM_REPORT_KEY_NTF_MQ".message.text.1"
#define APM_REPORT_KEY_NTF_MAP                    APM_REPORT_KEY_NTF_MQ".message.map.1"
#define APM_REPORT_KEY_NTF_BIN                    APM_REPORT_KEY_NTF_MQ".message.binary.1"
#define APM_REPORT_KEY_NTF_PRIORITY               APM_REPORT_KEY_NTF_MQ".priority"

//REQUEST
#define APM_REPORT_KEY_REQ_MQ                     APM_REPORT_KEY_REQ".mq"
#define APM_REPORT_KEY_REQ_QUEUE                  APM_REPORT_KEY_REQ_MQ".queue"
#define APM_REPORT_KEY_REQ_TOPIC                  APM_REPORT_KEY_REQ_MQ".topic"
#define APM_REPORT_KEY_REQ_METHOD                 APM_REPORT_KEY_REQ_MQ".method"
#define APM_REPORT_KEY_REQ_TYPE                   APM_REPORT_KEY_REQ_MQ".message.type"
#define APM_REPORT_KEY_REQ_TEXT                   APM_REPORT_KEY_REQ_MQ".message.text"
#define APM_REPORT_KEY_REQ_MAP                    APM_REPORT_KEY_REQ_MQ".message.map"
#define APM_REPORT_KEY_REQ_BIN                    APM_REPORT_KEY_REQ_MQ".message.binary"
#define APM_REPORT_KEY_REQ_PRIORITY               APM_REPORT_KEY_REQ_MQ".priority"


//RESPONSE
//#define APM_REPORT_KEY_RESP_MQ                     APM_REPORT_KEY_RESP".mq"
//#define APM_REPORT_KEY_RESP_METHOD                 APM_REPORT_KEY_RESP_MQ".method"
//#define APM_REPORT_KEY_RESP_TYPE                   APM_REPORT_KEY_RESP_MQ".message.type.1"
//#define APM_REPORT_KEY_RESP_TEXT                   APM_REPORT_KEY_RESP_MQ".message.text"
//#define APM_REPORT_KEY_RESP_MAP                    APM_REPORT_KEY_RESP_MQ".message.map"
//#define APM_REPORT_KEY_RESP_BIN                    APM_REPORT_KEY_RESP_MQ".message.binary"
//#define APM_REPORT_KEY_RESP_PRIORITY               APM_REPORT_KEY_RESP_MQ".priority"

/* 8位小头节序转到本地字节序 */
#define pntohl(p)  ((unsigned long long)*((const unsigned char *)(p + 0)) << 56 | \
                    (unsigned long long)*((const unsigned char *)(p + 1)) << 48 | \
                    (unsigned long long)*((const unsigned char *)(p + 2)) << 40 | \
                    (unsigned long long)*((const unsigned char *)(p + 1)) << 32 | \
                    (unsigned long long)*((const unsigned char *)(p + 2)) << 24 | \
                    (unsigned long long)*((const unsigned char *)(p + 1)) << 16 | \
                    (unsigned long long)*((const unsigned char *)(p + 2)) << 8 | \
                    (unsigned long long)*((const unsigned char *)(p + 1)) << 0)

/* 4位小头节序转到本地字节序 */
#define pntohi(p)  ((unsigned int)*((const unsigned char *)(p + 0)) << 24 | \
                    (unsigned int)*((const unsigned char *)(p + 1)) << 16 | \
                    (unsigned int)*((const unsigned char *)(p + 2)) << 8 | \
                    (unsigned int)*((const unsigned char *)(p + 3)) << 0)

/* 2位小头节序转到本地字节序 */
#define pntohs(p)  ((unsigned int)*((const unsigned char *)(p + 0)) << 8 | \
                    (unsigned int)*((const unsigned char *)(p + 1)) << 0)

/*! jboss 私有信息储存 */
typedef struct __L7session_jboss_private
{
    Frbyte_Packet *p_st_data;            // 数据内容

    char arr_session_id[APM_UUID_SIZE];
    struct timeval st_login_timestamp;
    char *p_user_name;
    char *p_title;

    int is_topic;
    int is_message;
    int i_flag_report;
    int i_use_request;
    int i_flag_data_type;
    int i_session;
    int i_data_len;

    unsigned long ul_seq;
    L4_transaction st_l4_trans;

    Frlist_header *p_lst_comm_tmp;                          //数据  activeMQ comm
    Frlist_header *p_lst_req_tmp;                          //数据  activeMQ req
    Frlist_header *p_lst_mq_tmp;                          //数据  activeMQ req

    Frreport_body_data *p_st_body_data_req;
    Frreport_body_data *p_st_body_data_resp;
}L7session_jboss_private;

int jboss_connection_parse(Frbyte_Packet *p_st_data, L7session_jboss_private *p_st_private, int i_flag_need);
int jboss_message_parse(Frbyte_Packet *p_st_data, Frreport_body_data *p_st_body_data, L7session_jboss_private *p_st_private, int i_flag_need);
int jboss_sub_parse(Frbyte_Packet *p_st_data, Frreport_body_data *p_st_body_data, L7session_jboss_private *p_st_private, int i_flag_need);

int jboss_content_parse(Frbyte_Packet *p_st_data, Frreport_body_data *p_st_body_data, L7session_jboss_private *p_st_private, int i_flag_need);

int jboss_session_parse(Frbyte_Packet *p_st_data, L7session_jboss_private *p_st_private, int i_flag_need);

#endif
